package com.pll.controller.Merchant;

import com.pll.controller.Merchant.vo.MerchantAuthenticationVo;
import com.pll.dto.ResponseDto;
import com.pll.service.MerchantService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName MerchantController
 * @Description TODO
 * @Author 小鹿
 * @Date 2025/6/14 17:34
 */
@Tag(name = "MerchantController")
@RestController
@RequestMapping("/merchant")
public class MerchantController
{
    @Autowired
    private MerchantService merchantService;
    @Operation(summary = "获取商家状态", description = "通过用户名获取商家状态")
    @GetMapping("/getMerchantStatus")
    public ResponseDto getMerchantStatus(@RequestParam("account") String account)
    {
        return merchantService.getMerchantStatus(account);
    }
    @Operation(summary = "处理商户认证", description = "通过商家传入的审核材料进行审核,参数会通过@Validated校验是否有错误")
    @PostMapping("/authentication")
    public ResponseDto MerchantAuthentication(@ModelAttribute @Validated MerchantAuthenticationVo merchantAuthenticationVo,
                                              BindingResult bindingResult)
    {
        // 处理校验错误
        if (bindingResult.hasErrors()) {
            String errorMsg = bindingResult.getFieldError().getDefaultMessage();
            return ResponseDto.err(400, errorMsg);
        }
        return merchantService.MerchantAuthentication(merchantAuthenticationVo);
    }

}